package com.lntea.redis;

import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.SortingParams;

public class KeyDemo {
	Jedis jedis;
	
	@Before
	public void connect(){
		jedis = new Jedis("192.168.1.108", 6379);
	}
	
	@Test
	public void keys(){
		Set<String> set = jedis.keys("*");
		System.out.println("keys result: "+set.toString());
	}
	
	@Test
	public void del(){
		Long result = jedis.del("abc");
		System.out.println("del result: "+result);
	}
	
	@Test
	public void move(){
		//move key to specified index db
		//String db = jedis.select(1);
		//System.out.println("db: "+db);
		Long result = jedis.move("number", 0);
		System.out.println("move result: "+result);
	}
	
	@Test
	public void rename(){
		String result = jedis.rename("number", "num");
		System.out.println("rename result: "+result);
	}
	
	@Test
	public void renamenx(){
		Long result = jedis.renamenx("num", "zset");
		System.out.println("renamenx result: "+result);
	}
	
	@Test
	public void expire(){
		Long result = jedis.expire("t1", 10);
		System.out.println("expire result: "+result);
	}
	
	@Test
	public void ttl(){
		Long result = jedis.ttl("num");
		System.out.println("ttl result: "+result);
	}
	
	@Test
	public void persist(){
		Long result = jedis.persist("num");
		System.out.println("persist result: "+result);
	}
	
	@Test
	public void randomkey(){
		String key = jedis.randomKey();
		System.out.println("randomkey: "+key);
	}
	
	@Test
	public void type(){
		String type = jedis.type("zset");
		System.out.println("type: "+type);
	}
	
	@Test
	public void sort(){
		SortingParams sortingParam = new SortingParams();
		sortingParam.by("weigth_1");
		sortingParam.get("object_1");
		Long result = jedis.sort("zset", sortingParam, "out");
		System.out.println("sort result: "+result);
	}
}
